#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int maxn = 1e8 + 100;
bool dp[maxn];
vector<int> primes;

void init(int n) {
    for (int i = 0; i <= n; i++)dp[i] = true;
    dp[0] = dp[1] = false;
    for (int i = 2; i <= n / i; i++) {
        if (dp[i]) {
            for (int j = 2 * i; j <= n; j += i) {
                dp[j] = false;
            }
        }
    }
}

ll r(ll n) {
    ll m = 0;
    while (n > 0) {
        m = m * 10 + n % 10;
        n /= 10;
    }
    return m;
}

int main() {
    ll a, b;
    while (cin >> a >> b) {
        init(b);
        for (ll i = a; i <= b; i++) {
            if (dp[i] && r(i) == i) {
                cout << i << endl;
            }
        }
        cout << endl;
    }

    return 0;
}